<template>

    <div class="qiamnDaoMian">

        <div class="qianTop">
            <div>

            </div>
            <div class="meetInfo">
                <img src="../assets/qiang/ceTop.png" alt="留言墙">
                <div> {{ form.signatureName }}</div>
                <div>会议日期：{{ form.signatureStartTime }}</div>
            </div>
            <div></div>
            <div class="erCode">
                <div>
                    完成检测人数：<span>{{ totalNum }}</span>
                </div>
                <div>
                    下降人数：<span>{{ downNum }}</span>
                </div>
                <div>
                    上升人数：<span>{{ upNum }}</span>
                </div>
                <div>
                    有效率：<span>{{ ((((downNum / totalNum) || 0).toFixed(2)) * 100) + '%' }}</span>
                </div>
            </div>
        </div>
        <div class="canleBox">
            <div @click="startHandle">
                <i class="el-icon-video-play" v-if="!startFlag"></i>
                <i class="el-icon-video-pause" v-else></i>
            </div>
            <div style="margin-top: 30px;">
                <i class="el-icon-refresh" @click="typeFlag = !typeFlag"></i>
            </div>
        </div>

        <!-- 列表 开始 -->
        <div class="staList">
            <div name="scrollBox" class="sentBox">
                <template v-if="typeFlag">
                    <div v-for="(item, index) in sentenctlist" :key="index"
                        :class="item.testNum < 0 ? 'infoBox1 infoBox' : 'infoBox'">
                        <div>姓名：{{ item.userName }}</div>
                        <div class="imgCon">
                            <div>
                                <img :src="item.beforeImg" v-if="item.isHaveBeforeImg" alt="">
                                <div>
                                    <span v-if="item.figure1 != ''"> 谷丙转氨酶：<span>{{ item.figure1 }}</span> </span>
                                </div>
                            </div>
                            <img src="../assets/qiang/vs.png" alt="">
                            <div>
                                <img :src="item.afterImg" v-if="item.isHaveAfterImg" alt="">
                                <div>
                                    <span v-if="item.figure4 != ''"> 谷丙转氨酶：<span>{{ item.figure4 }}
                                            <img v-if="Number(item.figure4) > Number(item.figure1)"
                                                src="../assets/qiang/up.png" class="cross" alt="">
                                            <img v-if="Number(item.figure4) < Number(item.figure1)"
                                                src="../assets/qiang/down.png" class="cross" alt="">
                                        </span>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>

                </template>
                <template v-else>
                    <div class="photoBox photoBox1" v-for="(item, index) in sentenctlist" :key="index">
                        <div class="photoTop">
                            <div>使用前</div>
                            <div>姓名：{{ item.userName }}</div>
                            <div>使用后</div>
                        </div>
                        <div class="resultBox">
                            <div class="resItem">
                                <div v-if="item.figure1 != ''">
                                    谷丙转氨酶
                                    <div>
                                        {{ item.figure1 }}
                                        <div
                                            :style="{ width: (((item.figure1 - 0) + 200) > 300 ? 300 : (item.figure1 - 0) + 200) + 'px' }">
                                        </div>
                                    </div>
                                </div>
                                <div v-if="item.figure4 != ''">
                                    <div>
                                        <div
                                            :style="{ width: (((item.figure4 - 0) + 200) > 300 ? 300 : (item.figure4 - 0) + 200) + 'px' }">
                                            <div :class="(item.figure4 - item.figure1) > 0 ? 'innerLine' : 'innerLine2 '"
                                                :style="{ width: (Math.abs(item.figure4 - item.figure1)) + 'px' }">
                                            </div>
                                        </div>
                                        {{ item.figure4 }}
                                        <img v-if="Number(item.figure4) > Number(item.figure1)"
                                            src="../assets/qiang/up.png" class="cross" alt="">
                                        <img v-if="Number(item.figure4) < Number(item.figure1)"
                                            src="../assets/qiang/down.png" class="cross" alt="">
                                    </div> 谷丙转氨酶
                                </div>
                            </div>
                        </div>
                        <div :class="item.testNum < 0 ? 'imgBox imgBox1' : 'imgBox'">
                            <div>
                                <img :src="item.beforeImg" v-if="item.isHaveBeforeImg" alt="">
                            </div>
                            <img src="../assets/qiang/vs2.png" alt="">
                            <div>
                                <img :src="item.afterImg" v-if="item.isHaveAfterImg" alt="">
                            </div>
                        </div>
                    </div>
                </template>


            </div>
        </div>
        <!-- 列表 结束 -->

        <!--   -->
        <div class="diaBox" v-if="showFlag">
            <div class="userBox1">
                <div class="photoBox">
                    <div class="photoTop">
                        <div>使用前</div>
                        <div>姓名：{{ nowSentenctInfo.userName }}</div>
                        <div>使用后</div>
                    </div>
                    <div class="resultBox">
                        <div class="resItem">
                            <div v-if="nowSentenctInfo.figure1 != ''">
                                谷丙转氨酶
                                <div>
                                    <template></template>
                                    {{ nowSentenctInfo.figure1 }}
                                    <div
                                        :style="{ width: (((nowSentenctInfo.figure1 - 0) + 200) > 300 ? 300 : (nowSentenctInfo.figure1 - 0) + 200) + 'px' }">
                                    </div>
                                </div>
                            </div>
                            <div v-if="nowSentenctInfo.figure4 != ''">
                                <div>
                                    <div
                                        :style="{ width: (((nowSentenctInfo.figure4 - 0) + 200) > 300 ? 300 : (nowSentenctInfo.figure4 - 0) + 200) + 'px' }">
                                        <div :class="(nowSentenctInfo.figure4 - nowSentenctInfo.figure1) > 0 ? 'innerLine' : 'innerLine2 '"
                                            :style="{ width: (Math.abs(nowSentenctInfo.figure4 - nowSentenctInfo.figure1)) + 'px' }">
                                        </div>
                                    </div>
                                    {{ nowSentenctInfo.figure4 }}
                                    <img v-if="Number(nowSentenctInfo.figure4) > Number(nowSentenctInfo.figure1)"
                                        src="../assets/qiang/up.png" class="cross" alt="">
                                    <img v-if="Number(nowSentenctInfo.figure4) < Number(nowSentenctInfo.figure1)"
                                        src="../assets/qiang/down.png" class="cross" alt="">
                                </div> 谷丙转氨酶
                            </div>
                        </div>

                    </div>
                    <div :class="nowSentenctInfo.testNum < 0 ? 'imgBox imgBox1' : 'imgBox'">
                        <div>
                            <img :src="nowSentenctInfo.beforeImg" v-if="nowSentenctInfo.isHaveBeforeImg" alt="">
                        </div>
                        <img src="../assets/qiang/vs2.png" alt="">
                        <div>
                            <img :src="nowSentenctInfo.afterImg" v-if="nowSentenctInfo.isHaveAfterImg" alt="">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>


<script>

export default {
    name: 'photoWall',
    data() {
        return {
            startFlag: false,
            form: {},
            sentenctlist: [],
            showFlag: false,
            nowSentenctInfo: '',
            num: localStorage.sentNum == undefined || localStorage.sentNum == NaN ? 0 : localStorage.sentNum,
            typeFlag: false,

            totalNum: 0, //总检测人数
            downNum: 0, // 下降人数
            upNum: 0, // 上升人数

        }
    },
    created() {
        if (localStorage.form != undefined) {
            this.form = JSON.parse(localStorage.form)
            console.log(this.form);
        }
        if (localStorage.sentenceList != undefined) {
            this.sentenctlist = JSON.parse(localStorage.sentenceList)
            this.handleData()
        }
        this.openWeb()

    },
    mounted() {
        this.updateScrollTop();
    },
    methods: {
        handleData() {
            console.log(this.sentenctlist);
            this.sentenctlist = this.sentenctlist.sort((a, b) => {
                return b.testNum - a.testNum
            })
            this.totalNum = 0, this.downNum = 0, this.upNum = 0;

            this.sentenctlist.forEach(item => {
                if (item.figure1 != 0 && item.figure4 != '') {
                    this.totalNum++
                }
                if (item.figure4 != '') {
                    if (item.testNum > 0) {
                        this.downNum++
                    } else if (item.testNum < 0) {
                        this.upNum++
                    }
                }
            })
        },
        startHandle() {
            if (this.startFlag) {
                // 暂停弹窗
                clearInterval(this.showTimer)
                this.showFlag = false
                console.log(this.num);
                localStorage.sentNum = this.num
                this.startFlag = false
            } else {
                // 开始弹窗
                this.showFlag = true
                this.startFlag = true
                this.num = localStorage.sentNum || 0
                this.loops()
            }
        },

        loops() {
            console.log(this.sentenctlist);
            console.log(this.num);

            this.nowSentenctInfo = this.sentenctlist[this.num];
            console.log(this.nowSentenctInfo);

            if (!this.nowSentenctInfo) {
                this.num = 0
                this.nowSentenctInfo = this.sentenctlist[this.num];
            }


            // return
            this.showFlag = true;
            this.showTimer = setInterval(() => {
                if (this.num == this.sentenctlist.length - 1) {
                    this.num = 0;
                } else {
                    this.num++;
                }

                this.nowSentenctInfo = this.sentenctlist[this.num];
                console.log(this.nowSentenctInfo);
                console.log(this.num);
            }, 10000);


        },


        openWeb() {
            if (typeof WebSocket == "undefined") {
                console.log("您的浏览器不支持WebSocket");
            } else {
                console.log("您的浏览器支持WebSocket");
                var socketUrl = "wss://www.ccclkj.cn:2033/imserver/" + -1;
                // var socketUrl = "http://192.168.0.111:2033/imserver/" + -1;
                // socketUrl = socketUrl.replace("https", "ws").replace("http", "ws");
                console.log(socketUrl);
                if (this.socket != null) {
                    this.socket.close();
                    this.socket = null;
                }
                //打开事件
                this.socket = new WebSocket(socketUrl);
                //打开事件
                this.socket.onopen = function () {
                    console.log("websocket已打开");
                };
                var _this = this;
                //获得消息事件
                _this.socket.onmessage = function (msg) {
                    console.log(msg.data);
                    if (msg.data == "连接成功") {
                        _this.$message({
                            type: "success",
                            duration: 500,
                            offset: "400",
                            message: "连接成功",
                        });
                    }
                    if (msg.data != "连接成功") {
                        var data = JSON.parse(msg.data);
                        console.log(data);
                        console.log(JSON.parse(data.content));
                        _this.sentenctlist = JSON.parse(data.content)
                        console.log(_this.sentenctlist);
                        _this.sentenctlist.forEach(item => {
                            item.testNum = Number(item.figure1) - Number(item.figure4)
                        })

                        _this.handleData()

                        localStorage.sentenceList = JSON.stringify(_this.sentenctlist);
                    }
                };
                //关闭事件
                this.socket.onclose = function () {
                    console.log("websocket已关闭");
                };
                //发生了错误事件
                this.socket.onerror = function () {
                    _this.$message.warning("连接失败");
                    console.log("websocket发生了错误");
                };
            }
        },

        updateData() {
            this.sentenctlist.push(...this.sentenctlist)
        },

        //元素滚动
        updateScrollTop() {
            const scrollList = document.getElementsByName("scrollBox");
            for (let i = 0; i < scrollList.length; i++) {
                const x = scrollList[i];
                this.scrollThen(x).then();
            }
        },
        async scrollThen(x) {
            var that = this;
            do {
                await new Promise((resolve) => {
                    setTimeout(() => {
                        resolve();
                    }, 40);
                });
                if (parseFloat(x.clientHeight / x.scrollHeight) < 1) {
                    if (x.scrollHeight - x.scrollTop - x.clientHeight < 5) {
                        // x.scrollTop = 0;
                        that.updateData()
                    } else {
                        x.scrollTop++;
                    }
                }
            } while (true);
        },

    },

}
</script>
<style lang="less" scoped>
.qiamnDaoMian {
    width: 100%;
    height: 100vh;
    overflow: hidden;
    background-image: url(../assets/qiang/bottomBg.png);
    background-size: 100% 100%;

    .qianTop {
        box-sizing: border-box;
        padding: 40px 74px;
        position: relative;
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        // height: 30vh;
        // box-shadow: 1px 2px 4px 0px rgba(0, 0, 0, 0.4);
        background-image: url(../assets/qiang/topBg.png);
        background-size: 100% 100%;

        img {
            width: 254px;
            height: 76px;
        }

        .meetInfo {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 36px;
            color: #fff;
        }

        .meetInfo>div:nth-child(2) {
            margin: 40px 0;
        }

        .meetInfo>div:nth-child(3) {
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 18px;
            color: #999999;
        }

    }

    ::-webkit-scrollbar {
        display: none;
    }

    .staList {
        position: relative;
        box-sizing: border-box;
        padding: 16px 62px;
        box-sizing: border-box;

        width: 100%;
        height: 70vh;
        overflow-y: scroll;
        z-index: 10;
    }
}



.erCode {
    position: absolute;
    right: 80px;
    display: flex;
    flex-direction: column;
    align-items: start;
    justify-content: start;
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 28px;
    color: #0B1532;
    text-shadow: 1px 2px 4px rgba(255, 255, 255, 0.4);
    background: linear-gradient(0deg, #FEFEFE 0%, #E297A0 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.erCode>div {
    margin-bottom: 10px;
}

.erCode>div>span {
    font-size: 34px;
}

.infoBox {
    padding: 12px;
    margin-bottom: 160px;
    display: flex;
    flex-direction: column;
    align-content: center;
    width: 48%;
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 40px;
    color: #0B1532;
    text-shadow: 1px 2px 4px rgba(255, 255, 255, 0.4);
    background: linear-gradient(0deg, #FEFEFE 0%, #E297A0 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    border: 3px solid transparent;
    border-radius: 12px;

}

.infoBox1 {
    border: 3px solid #FEAC3B;
}

.infoBox>div {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.infoBox>div:first-child {
    margin-bottom: 80px;
}

.imgCon {
    width: 100%;
}

.imgCon>div {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 352px;
    height: 469px;
    border-radius: 16px;
    // overflow: hidden;
}

.imgCon>div>div {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: absolute;
    top: -70px;
    width: 100%;
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 34px;
    color: #0B1532;
    text-shadow: 1px 2px 4px rgba(255, 255, 255, 0.4);
    background: linear-gradient(0deg, #FEFEFE 0%, #E297A0 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.imgCon>div>div>span {
    // margin-top: 12px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.imgCon>div>div>span>span {
    display: flex;
    align-items: center;
}

.imgCon>div>img {
    width: 328px;
    height: 446px;
}

.imgCon>div:first-child {
    background-image: url(../assets/qiang/imgBg1.png);
    background-size: 100% 100%;
}

// .imgCon>div:first-child::before,
// .imgCon>div:last-child::before {
//     position: absolute;
//     top: -72px;
//     content: '使用前';
//     font-family: Microsoft YaHei;
//     font-weight: bold;
//     font-size: 34px;
//     color: #0B1532;
//     text-shadow: 1px 2px 4px rgba(255, 255, 255, 0.4);
//     background: linear-gradient(0deg, #FEFEFE 0%, #E297A0 100%);
//     background-clip: text;
//     -webkit-background-clip: text;
//     -webkit-text-fill-color: transparent;
// }

// .imgCon>div:last-child::before {
//     content: '使用后';
// }


.imgCon>div:first-child::after,
.imgCon>div:last-child::after {
    position: absolute;
    right: -44px;
    bottom: 0px;
    content: '使用前';
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 28px;
    color: #0B1532;
    text-shadow: 1px 2px 4px rgba(255, 255, 255, 0.4);
    background: linear-gradient(0deg, #FEFEFE 0%, #E297A0 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    width: 34px;
    word-wrap: break-word;
    letter-spacing: 20px
}


.imgCon>div:last-child::after {
    content: '使用后';
    right: 0px !important;
    left: -44px !important;
}

.imgCon>img {
    width: 106px;
    height: 100px;
}

.cross {
    width: 32px;
    height: 40px;
    transform: scale(.8);
}

.imgCon>div:nth-child(3) {
    background-image: url(../assets/qiang/imgBg2.png);
    background-size: 100% 100%;
}

// .infoBox>div>img {
//     width: 160px;
//     height: 160px;
// }

.sentBox {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    box-sizing: border-box;
    padding-bottom: 100px;
    margin: 10px 0;
    flex: 1;
    width: 100%;
    height: 70vh;
    overflow-y: auto;
}

.sentBox::-webkit-scrollbar {
    display: none;
}

.sentBox>.sentenceItem:first-child {
    margin-top: 0px !important;
}

.sentBox>div {
    position: relative;
}

.diaBox {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, .3);
    z-index: 10;
}


.userBox1 {
    width: 100%;
    height: 100%;
    background-image: url(../assets/qiang/photoBg.png);
    background-size: 100% 100%;
}

.userBox1 {
    animation: scaleAnmite 10s linear infinite;
    -webkit-animation: scaleAnmite 10s linear infinite;
}

@keyframes scaleAnmite {
    0% {
        transform: scale(0);
    }

    0.5% {
        transform: scale(0.1);
    }

    1% {
        transform: scale(0.2);
    }

    1.5% {
        transform: scale(0.3);
    }

    2% {
        transform: scale(0.4);
    }

    2.5% {
        transform: scale(0.5);
    }

    3% {
        transform: scale(0.6);
    }

    3.5% {
        transform: scale(0.7);
    }

    4% {
        transform: scale(0.8);
    }

    4.5% {
        transform: scale(0.9);
    }

    5% {
        transform: scale(1);
    }

    95% {
        transform: scale(1);
    }

    95.5% {
        transform: scale(0.9);
    }

    96% {
        transform: scale(0.8);
    }

    96.5% {
        transform: scale(0.7);
    }

    97% {
        transform: scale(0.6);
    }

    97.5% {
        transform: scale(0.5);
    }

    98% {
        transform: scale(0.4);
    }

    98.5% {
        transform: scale(0.3);
    }

    99% {
        transform: scale(0.2);
    }

    99.5% {
        transform: scale(0.1);
    }

    100% {
        transform: scale(0);
    }

    100% {
        transform: scale(0);
    }
}

.canleBox {
    position: absolute;
    top: 36px;
    right: 20px;
    z-index: 12;
    cursor: pointer;
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    // text-decoration: underline;
    color: #fd0000;
    // border-bottom: 1px solid #0B1532;
}


.photoBox {
    box-sizing: border-box;
    padding: 200px 196px 224px;
    width: 100%;
    // height: 100%;
}

.photoBox1 {
    margin-bottom: 100px;
    padding-top: 0px !important;
    padding-bottom: 0px !important;
}



.photoTop {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    width: 100%;

    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 48px;
    color: #0B1532;
    text-shadow: 1px 2px 4px rgba(255, 255, 255, 0.4);
    background: linear-gradient(0deg, #FEFEFE 0%, #E297A0 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.photoTop>div:not(:nth-child(2)) {
    font-size: 34px;
}

.resultBox {
    width: 100%;
}

.resItem {
    margin-top: 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.resItem>div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 50%;
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 42px;
    color: #0B1532;
    text-shadow: 1px 2px 4px rgba(255, 255, 255, 0.4);
    background: linear-gradient(0deg, #FEFEFE 0%, #E297A0 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.resItem>div>div {
    display: flex;
    align-items: center;
    font-size: 46px;
}

.resItem>div>div>div {
    position: relative;
    margin-right: 2px;
    margin-left: 20px;
    // width: 300px;
    height: 41px;
    background: linear-gradient(0deg, #FEFEFE, #E297A0);
    box-shadow: 1px 2px 4px 0px rgba(0, 0, 0, 0.4);
}

.resItem>div>div>div>div {
    position: absolute;
    right: 0px;
}



.resItem>div:nth-child(2)>div>div {
    margin-left: 2px;
    margin-right: 20px;
}

.innerLine {
    height: 100%;
    background: #FEAC3B;
}

.innerLine2 {
    height: 100%;
    background: #40FF40;
}

.imgBox {
    margin-top: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.imgBox1 {
    box-sizing: border-box;
    padding: 12px;
    border: 3px solid #FEAC3B;
    border-radius: 12px;
}

.imgBox>div {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 352px;
    height: 469px;
}

.imgBox>div>img {
    width: 328px;
    height: 446px;
}

.imgBox>div:first-child {
    background-image: url(../assets/qiang/imgBg1.png);
    background-size: 100% 100%;
}

.imgBox>div:nth-child(3) {
    background-image: url(../assets/qiang/imgBg2.png);
    background-size: 100% 100%;
}


.imgBox>div:first-child::after,
.imgBox>div:last-child::after {
    position: absolute;
    right: -80px;
    bottom: 0px;
    content: '使用前';
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 48px;
    color: #0B1532;
    text-shadow: 1px 2px 4px rgba(255, 255, 255, 0.4);
    background: linear-gradient(0deg, #FEFEFE 0%, #E297A0 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    width: 50px;
    word-wrap: break-word;
    letter-spacing: 20px
}


.imgBox>div:last-child::after {
    content: '使用后';
    right: 0px !important;
    left: -80px !important;
}

.imgBox>img {
    width: 200px;

}
</style>
